package first.group.ssh.authorize;

import first.group.ssh.packet.Packet;
import first.group.ssh.packet.writer.StringWriter;
import java.io.IOException;
import java.nio.ByteBuffer;

public class PasswordAuthorization extends Authorization {

    public final String password;
    
    public PasswordAuthorization(String password) {
        this.password = password;
    }

    @Override
    public void read(Packet packet) throws IOException {
        throw new UnsupportedOperationException("PasswordAuthorization do not receive special packet");
    }

    @Override
    public String getName() {
        return "password";
    }

    @Override
    public byte[] getPayload() {
        var buffer = ByteBuffer.allocate(1024);
        buffer.put((byte) 0);
        StringWriter.writeString(buffer, password);
        buffer.flip();
        
        byte[] result = new byte[buffer.limit()];
        buffer.get(result);
        return result;
    }
}
